import java.util.LinkedList;

public class ChartGenerator 
{	
	public void constructFanOutChart(ChartVersion[] chartVersions, boolean relative)
	{

		for (ChartVersion ver : chartVersions)
		{
			ver.setSeriesData(getSeries(ver.getVersion(), true));
		}
		
		String title = "FanOut Histogram";
		String xAxisLabel = "FanOut";
		String yAxisLabel = "FanOut %";
		ChartWrapper cw = ChartWrapper.GetInstance();
		cw.CreateRelativeHistogram(title, xAxisLabel, yAxisLabel,
				chartVersions, false, true, relative);
	}
	
	public void constructFanInChart(ChartVersion[] chartVersions, boolean relative)
	{

		for (ChartVersion ver : chartVersions)
		{
			ver.setSeriesData(getSeries(ver.getVersion(), false));
		}
		
		String title = "FanIn Histogram";
		String xAxisLabel = "FanIn";
		String yAxisLabel = "FanIn %";
		ChartWrapper cw = ChartWrapper.GetInstance();
		cw.CreateRelativeHistogram(title, xAxisLabel, yAxisLabel,
				chartVersions, false, true, relative);
	}		
	
	/**
	 * Generates histogram data for the specified version
	 * @param version - The version.
	 * 
	 * @return - A hashtable containing the cumalative fanout results.
	 */

	private double[] getSeries(Version version, boolean fanOut)
	{
		LinkedList<MetricClass> metricClasses = version.getMetricClasses();
		double[] ret = new double[metricClasses.size()];
		
		int index = 0;
		for (MetricClass mc : metricClasses)
		{
			if (fanOut)
				ret[index++] = mc.getFanOutCount();
			else
				ret[index++] = mc.getFanInCount();
		}
		return ret;
	}

}
